package com.ruoyi.web.controller.activity.rank;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.activity.entity.ActivityRankConfig;
import com.ruoyi.activity.entity.RankConfigVO;
import com.ruoyi.activity.service.ActivityRankService;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/activity/rank")
public class RankController {
    @Resource
    private ActivityRankService activityRankService;

    @PreAuthorize("@ss.hasPermi('activity:rank:config:list')")
    @GetMapping(value = "/config/list")
    public Page<ActivityRankConfig> configList(Integer type,
                                               @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                               @RequestParam(value = "pageNum", defaultValue = "1") int pageNum){
        System.out.println(type);
        return activityRankService.getActivityRankConfigList(type,pageNum,pageSize);
    }

    @PreAuthorize("@ss.hasPermi('activity:rank:config:query')")
    @GetMapping(value = "/one/{id}")
    public AjaxResult getOneActivity(@PathVariable("id") Integer id){
        ActivityRankConfig config = activityRankService.getOneActivity(id);
        return AjaxResult.success(config);
    }

    @PreAuthorize("@ss.hasPermi('activity:rank:config:edit')")
    @PutMapping(value = "/update")
    public AjaxResult updateActivity(RankConfigVO configVO){
        activityRankService.updateActivity(configVO);
        return AjaxResult.success();
    }

    @PreAuthorize("@ss.hasPermi('activity:rank:config:add')")
    @PostMapping(value = "/add")
    public AjaxResult addActivity(RankConfigVO configVO){
        activityRankService.addActivity(configVO);
        return AjaxResult.success();
    }


    @PreAuthorize("@ss.hasPermi('activity:rank:config:del')")
    @DeleteMapping(value = "/delete/{id}")
    public AjaxResult deleteActivity(@PathVariable("id") Integer id){
        activityRankService.deleteActivity(id);
        return AjaxResult.success();
    }


    @GetMapping(value = "/labels")
    public AjaxResult getLabels(){
        return AjaxResult.success(activityRankService.getLabels());
    }
}
